package zulu.editorTest;

import static bogus.core.BogusCore.egl;
import owg.util.EntityBase;
import owg.util.InstanceList;
import owg.util.data.property.Property;
import owg.util.editor2d.entity.Placeable2D;
import owg.util.editor2d.entity.Scaleable2D;
import owg.util.editor2d.entity.Touchable2D;
import owg.util.euclidian.MatrixStack;
import owg.util.euclidian.V2D;

public class Dumdum extends EntityBase implements Placeable2D, Scaleable2D, Touchable2D {
	
	private String name;
	private V2D pos, speed;
	private float xScale, yScale;
	
	public final Property<String> bubbus = new Property<String>((param, oldValue, newValue) -> { 
			return newValue.substring(0, Math.min(newValue.length(), 4)); 
		}, "Bahb");
	
	public Dumdum(InstanceList list, V2D pos, float xScale, float yScale) {
		super(list, 0);
		this.pos = pos;
		speed = new V2D();
		this.xScale = xScale;
		this.yScale = yScale;
	}
	
	@Override
	public void setScale(float newXScale, float newYScale, boolean tentative) {
		xScale = newXScale;
		yScale = newYScale;
	}
	
	@Override
	public float getXScale() {
		return xScale;
	}
	
	@Override
	public float getYScale() {
		return yScale;
	}
	
	@Override
	public void setLocation(double x, double y, boolean tentative) {
		pos.set(x, y);
	}
	
	@Override
	public double getX() {
		return pos.x();
	}
	
	@Override
	public double getY() {
		return pos.y();
	}
	
	@Override
	public String getDefaultName() {
		return getClass().getSimpleName();
	}
	@Override
	public String toString() {
		return getName();
	}
	
	@Override
	public String getName() {
		return name;
	}
	
	@Override
	public void setName(String newName) {
		name = newName;
	}
	
	@Override
	public void beginStep() {
	}
	
	@Override
	public void step() {
		pos.add(speed);
	}
	
	@Override
	public void endStep() {
	}
	
	@Override
	public void render() {
		render(false);
	}
	@Override
	public void render(boolean shadeless) {
		MatrixStack m = egl.modelviewMatrix();
		m.push();
		m.translatef((float)pos.x(), (float)pos.y(), 0.0f);
		m.scalef(xScale, yScale, 1);
		egl.nwSquare.render();
		m.pop();
	}
	
	@Override
	public boolean touches(double x, double y) {
		return x >= pos.x() && y >= pos.y() && x < pos.x()+xScale && y < pos.y()+yScale;
	}
}
